package com.ds.lens.flink.monitor.eventsinkjob.function.notify.onduty;

import com.google.gson.JsonObject;
import com.ds.lens.data.common.util.HttpServiceClient;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OndutyClientWraper implements OndutyClient {
    private OndutyClient ondutyClient;
    private static final String message = "error occured.";

    public OndutyClientWraper(String ondutyUrl) {
        ondutyClient = HttpServiceClient.getRestClient(OndutyClient.class, ondutyUrl, false);
    }

    @Override
    public Reply sendAlarm(Notice notice) {
        try {
            return ondutyClient.sendAlarm(notice);
        } catch (Exception e) {
            log.error(message, e);
            return null;
        }
    }

    @Override
    public JsonObject getDetail(String authorization, String ticketId) {
        try {
            return ondutyClient.getDetail(authorization, ticketId);
        } catch (Exception e) {
            log.error(message, e);
            return new JsonObject();
        }
    }

    @Override
    public JsonObject appendComment(String authorization, Comment comment) {
        try {
            return ondutyClient.appendComment(authorization, comment);
        } catch (Exception e) {
            log.error(message, e);
            return new JsonObject();
        }
    }
}
